<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<title>添加渠道</title>
		<link rel="stylesheet" type="text/css" href="/webapp/css/easyui.css">
	    <link rel="stylesheet" type="text/css" href="/webapp/css/icon.css">
        <link rel="stylesheet" type="text/css" href="/webapp/css/color.css">
        <link rel="stylesheet" type="text/css" href="/webapp/css/public.css">
	    <script type="text/javascript" src="/webapp/js/lib/jquery.min.js"></script>
	    <script type="text/javascript" src="/webapp/js/lib/jquery.easyui.min.js"></script>
	    <script type="text/javascript" src="/webapp/js/lib/ajaxfileupload.js"></script>
	    <script type="text/javascript" src="/webapp/js/common/config.js"></script>
	</head>
	<body class="easyui-layout">
		<div class="easyui-container-fluid">
			<div class="easyui-panel" style="width:100%;border: none;">
              <div id="nav" class="nav">
                
              </div>
              <div class="easyui-panel">
              	<form id="ff">
              		
                  <div style="margin-bottom:20px;">
                         <label class="item-label">*名称：</label>
                         <input type="text" class="easyui-textbox" name="name" data-options="required:true" prompt="请输入渠道名称" style="width:170px;"/>
                  </div>
              		<div style="margin-bottom:20px;">
                           <label class="item-label">周上报：</label>
                           <select class="easyui-combobox" name="reportWeekData" style="width:170px;" data-options="panelHeight:'auto'">
                                  <option value="true">是</option>
                                  <option value="false">否</option>
                           </select>
                           <label class="item-label">月上报：</label>
                           <select class="easyui-combobox" name="reportMonthData" style="width:170px;" data-options="panelHeight:'auto'">
                                  <option value="true">是</option>
                                  <option value="false">否</option>
                           </select>
                        <label class="item-label"  style="width:120px;">月为合并周：</label>
                        <select class="easyui-combobox" name="mergeWeekFlag" style="width:170px;" data-options="panelHeight:'auto'">
                            <option value="false">否</option>
                            <option value="true">是</option>
                        </select>
                    </div>
                    <div style="margin-bottom:20px;">
                           <label class="item-label" >线上渠道：</label>
                           <select class="easyui-combobox" name="onlineChannel" style="width:170px;" data-options="panelHeight:'auto'" >
                                  <option value="true">是</option>
                                  <option value="false">否</option>
                           </select>
                           <label class="item-label">退货处理：</label>
                           <select class="easyui-combobox" name="handleRejectSales" style="width:170px;" data-options="panelHeight:'auto'">
                                  <option value="true">是</option>
                                  <option value="false">否</option>
                           </select>
                           <label class="item-label" style="width:120px;">数据上报格式：</label>
                           <select class="easyui-combobox" name="recordReportFormat" style="width:170px;" data-options="panelHeight:'auto'">
                                  <option value="SINGLE">单条上报</option>
                                  <option value="MULTI">多条上报</option>
                           </select>
                    </div>
                    <div style="margin-bottom:20px;">
                           <label class="item-label">周报处理人：</label>
                           <select id="weekDataOption" class="easyui-combobox" name="weekDataHandleUserId" style="width:170px;" data-options="panelHeight:'auto'">
                           </select>
                           <label class="item-label">月报处理人：</label>
                           <select id="monthDataOption" class="easyui-combobox" name="monthDataHandleUserId"  style="width:170px;" data-options="panelHeight:'auto'">
                           </select>
	              		   <label class="item-label" style="width:120px;">数据联系人：</label>
	              		   <input type="text" class="easyui-textbox" name="dataGatherer" style="width:170px;"/>
                    </div>
                    <div style="margin-bottom:20px;">
                        <label class="item-label">包含日期：</label>
                        <select id="channelDate" class="easyui-combobox" name="channelDate" style="width:170px;" data-options="panelHeight:'auto'">
                            <option value="false">否</option>
                            <option value="true">是</option>
                        </select>
                        <label class="item-label">所属渠道码：</label>
                        <input type="text" class="easyui-textbox" name="qz" style="width:170px;"/>
                    </div>
              		<div style="margin-bottom:20px;">
              			<label class="item-label">备注：</label>
              			<input type="text" class="easyui-textbox" name="remark" multiline="true" style="width:440px;height:120px;"/>
              		</div>
              		<div style="margin-bottom:20px;margin-left:100px;">
                         <a href="javascript:void(0)" class="easyui-linkbutton c8" onclick="submitForm()" style="width:80px">保存</a>
                         <a href="javascript:void(0)" class="easyui-linkbutton" onclick="clearForm()" style="width:80px">取消</a>
                  </div>
              	</form>
              </div>
            </div>
        </div>
	</body>
  <script type="text/javascript">
      var id=getQueryParameter("id");
      $(function(){
        if(id){
            $.ajax({
              url:config.url +"/channel",
              type:'get',
              data:{id:id},
              xhrFields:{withCredentials:true},
              success:function(data){
                //填充表单
                  if(data){
                      $("#ff").form("load",changeProperty2String(data.content[0]));
                  }   
              },
              error:function(){

              }
            });
          }
          setNav();
          $.ajax({
              url:config.url+"/user/getAll",
              type:'get',
              xhrFields:{withCredentials:true},
              success:function (data) {
                  if(data){
                      data.unshift({id:"",username:"-请选择-"});
                      $("#weekDataOption,#monthDataOption").combobox({
                          data:data,
                          valueField:"id",
                          textField:"username"
                      });
                  }
              }
          });
      });
      function submitForm(){
          $("#ff").form("submit",{
               onSubmit:function(){
                  var valid = $(this).form('enableValidation').form('validate');
                  if(valid){
                      var channel = getFormData(document.getElementById("ff"));
                      var method = "POST",action="save";
                      if(id){
                          method = "PATCH";
                          channel.id = id;
                          action="updateChannel"
                      }
                      $.ajax({
                         url:config.url+"/channel/"+action,
                         type:method,
                         data:JSON.stringify(channel),
                         dataType:'json',
                         contentType:'application/json;charset=UTF-8',
                         beforeSend:function(){
                             $.messager.progress({
                                 title:"请稍等",
                                 interval:50,
                                 text:"操作进行中..."
                             });
                         },
                         complete:function(){
                             $.messager.progress("close");
                         },
                         xhrFields:{withCredentials:true},
                          success:function(data){
                              $.messager.progress("close");
                              $.messager.alert("提示","操作成功","info",function(){
                                  window.parent.closeCurrentTab(true);
                              });
                          },
                          error:function(XMLHttpRequest,textStatus,thrown){
                              $.messager.alert("提示","操作失败","error");
                          }
                      });
                       return false;
                    }
                    return false;
                  
               }
          });
          
      }
      function clearForm() {
          window.parent.closeCurrentTab();
      }
  </script>
</html>